package com.huaxinkai.mobile.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.transaction.Transactional;

import org.springframework.stereotype.Service;

import com.huaxinkai.entity.UserEntity;
import com.huaxinkai.mobile.service.IUserService;
import com.huaxinkai.service.impl.BaseService;

/**
 * User 服务类
 * @author liuzh
 * @data 2017年1月1日下午8:20:53
 */
@Service
@Transactional
@SuppressWarnings({"unchecked","rawtypes"})
public class UserService extends BaseService implements IUserService{
	
	/**
	 * 获取User
	 * @return List<User>
	 */
	@Override
	public List<UserEntity> getUsers() throws Exception{
		getCurrentSession();
		return query(UserEntity.class);
	}
	/**
	 * 获取User
	 * @return List<User>
	 */
	@Override
	public UserEntity getUser(int id)  throws Exception{
		getCurrentSession();
		return (UserEntity) query(UserEntity.class,id);
	}
	/**
	 * 增加User
	 * @return boolean
	 */
	@Override
	public boolean addUser(UserEntity user)  throws Exception{
		getCurrentSession();
		return insert(user);
	}
	/**
	 * 更新User
	 * @return boolean
	 */
	@Override
	public boolean updateUser(UserEntity user)  throws Exception{
		getCurrentSession();
		return update(user);
	}
	/**
	 * 删除User
	 * @return boolean
	 */
	@Override
	public boolean deleteUserById(int id)  throws Exception{
		getCurrentSession();
		return delete(id, "UserEntity");
	}
	
	@Override
	public UserEntity getUser(String name, String password) throws Exception {
		getCurrentSession();
		Map map = new HashMap();
		map.put("@name", name);
		map.put("@password", password);
		String sql = "from UserEntity where name='"+name+"' AND password = '"+password+"'";
		System.out.println(sql);
		UserEntity u = (UserEntity)queryOne(sql);
		return u;
	}
	
}
